<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php echo $commander->getListCommandsPanel('n-sa-a-d-sqlpager-sqlfilter-reload', ''); ?>
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
            <tr>
                <th class="first center">&nbsp;&nbsp;Id&nbsp;&nbsp;</th>
                <th class="nosort"><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></th>
                <th class="nosort"><?php echo ucfirst($txt->getWord('username')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('e-mail')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('company')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('user_group')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('access_level')); ?></th>
				<?php if($ac->getSetting('partner-accounts') > 0): ?>
				<th class="nosort"><?php echo ucfirst($txt->getWord('partner')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('clicks').' / '.$txt->getWord('views')); ?> 12m.</th>
				<?php endif; ?>
				<?php if(is_object($adc)): ?>
				<th class="nosort"><?php echo ucfirst($txt->getWord('ads')); ?></th>
				<th class="nosort"><?php echo ucfirst($txt->getWord('conversions')); ?></th>
				<?php endif; ?>
				<!--<th><?php echo ucfirst($txt->getWord('registered').' '.$txt->getWord('date')); ?></th>-->
				<!--<th><?php //echo ucfirst($txt->getWord('lastvisit').' '.$txt->getWord('date')); ?></th>-->
                <th class="nosort"><?php echo ucfirst($txt->getWord('active')); ?></th>
				<?php if($user->getLevel() > 4): ?>
				<th class="nosort"><?php echo ucfirst($txt->getWord('login')); ?></th>
				<?php endif; ?>
                <th class="nosort"><?php echo ucfirst($txt->getWord('edit')); ?></th>
                <!--<th class="last nosort"><?php echo ucfirst($txt->getWord('delete')); ?></th>-->
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>
<div id="add_dialog" title="<?php echo ucfirst($txt->getWord('new').' '.$txt->getWord('user')); ?>?" style="display:none; text-align:left;">
	<p>
		<?php echo ucfirst($txt->getWord('username')); ?><br />
		<input class="small" name="new_username" type="text" value="" maxlength="80" id="new_username" /><br /><br />
		<?php echo ucfirst($txt->getWord('email')); ?><br />
		<input class="small" name="new_email" type="text" value="" maxlength="80" id="new_email" /><br /><br />
		<?php echo ucfirst($txt->getWord('password')); ?><br />
		<input class="small" name="new_password" type="text" value="" maxlength="80" id="new_password" /><br /><br />
		<?php echo ucfirst($txt->getWord('password2')); ?><br />
		<input class="small" name="new_password2" type="text" value="" maxlength="80" id="new_password2" />
	</p>
</div>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('user')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete')); ?></p>
</div>
<div id="edit_dialog" title="<?php echo ucfirst($txt->getWord('edit').' '.$txt->getWord('user')); ?>?" style="display:none; text-align:left;">
	<div class="edit-form"></div>
</div>
<script type="text/javascript">
function addNewDialog(itemId)
{
	jQuery('#add_dialog').dialog('open');
	jQuery('#add_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:300,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('add')).' '.$txt->getWord('element'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=group", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					new_username: jQuery('#new_username').val(), 
					new_email: jQuery('#new_email').val(), 
					new_password: jQuery('#new_password').val(), 
					new_password2: jQuery('#new_password2').val()
				}).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}


function editDialog(itemId)
{
	jQuery('#edit_dialog').dialog('open');
	
	jQuery.ajax(
	{
		url: "ajax.php<?php echo $commander->getFormAction('ajax'); ?>&user="+itemId,
		cache: false,
	  	success: function(html)
	  	{ 
			jQuery('#edit_dialog .edit-form').empty();
			jQuery("#edit_dialog .edit-form").append(html);
		}
	});
	
	jQuery('#edit_dialog').dialog({
		bgiframe: true,
		resizable: true,
		draggable: true,
		modal: true,
		closeOnEscape: true,
		position: [400,100],
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('cancel')); ?>': function() 
			{ jQuery(this).dialog('close'); },
			'<?php echo ucfirst($txt->getWord('save')).' '.$txt->getWord('user'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&edit=user&user="+itemId, 
				{ 
					action:'editor_user', 
					Username: jQuery('#edit_dialog #Username').val(), 
					Email: jQuery('#edit_dialog #Email').val(), 
					Group: jQuery('#edit_dialog #Group').val(), 
					Level: jQuery('#edit_dialog #Level').val(),
					PartnerStatus: jQuery('#edit_dialog #PartnerStatus').val()
				}).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}

function deleteDialog(itemId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete')).' '.$txt->getWord('user'); ?>': function() 
			{
				jQuery.post("ajax.php?con=<?php echo $_GET['con']; ?>&list=<?php echo $_GET['list']; ?>", 
				{ 
					action:'<?php echo $commander->getPostAction(); ?>', 
					del_item_id: itemId} 
				).success(function() { loadItems(); });
				jQuery(this).dialog('close');
			}
		}
	});
}
<?php 
	$ac->loadUsersCount();
	$ac->Pager->calcPagesCount();
	
	$prev = 1;
	$next = 1;
	
	if($ac->Pager->getPagesCount() > $ac->Pager->getPageCurrent())
	{ $next = ($ac->Pager->getPageCurrent() + 1); }
	else
	{ $next = ($ac->Pager->getPageCurrent()); }
	
	if(($ac->Pager->getPageCurrent() > 1) && ($ac->Pager->getPagesCount() > $ac->Pager->getPageCurrent()))
	{ $prev = ($ac->Pager->getPageCurrent() - 1); }
?>
function loadItems(page)
{
	jQuery('table.item_list tbody').empty();
	jQuery('table.item_list tbody').html('<?php echo $commander->getComponentListLoading(); ?>'); 
	jQuery.ajax(
	{
		url: "ajax.php<?php echo $commander->getFormAction('ajax'); ?>&page=<?php echo $ac->Pager->getPageCurrent(); ?>&q=<?php echo $_REQUEST['q']; ?>",
		cache: false,
	  	success: function(html)
	  	{ 
			jQuery('table.item_list tr.loading').remove();
			jQuery("table.item_list tbody").append(html);
		}
	});
}
jQuery(document).ready(function() 
{ 
	jQuery("#page_first").attr('href', '?con=2&list=user&page=1&q=<?php echo $_REQUEST['q']; ?>');
	jQuery("#page_prev").attr('href', '?con=2&list=user&page=<?php echo $prev; ?>&q=<?php echo $_REQUEST['q']; ?>');
	
	jQuery("#page").val('<?php echo $ac->Pager->getPageCurrent(); ?>');
	jQuery("#pages-count").val('<?php echo $ac->Pager->getPagesCount(); ?>');
	
	jQuery("#page_next").attr('href', '?con=2&list=user&page=<?php echo $next; ?>&q=<?php echo $_REQUEST['q']; ?>');
	jQuery("#page_last").attr('href', '?con=2&list=user&page=<?php echo $ac->Pager->getPagesCount(); ?>&q=<?php echo $_REQUEST['q']; ?>');
	
	loadItems(0); 
});
</script>

